home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / doget.cmd < prev    next >
OS/2 REXX Batch file  |  1996-11-17  |  3KB  |  96 lines

  1. /* DOGET -- get's a resource from an HTTP server                 */
  2. /* ------------------------------------------------------------------- */
  3. /* Call as: DOGET [serveraddress [requeststring]]                   */
  4. /* ------------------------------------------------------------------- */
  5. /* This program requires that the RxSock.DLL be in your LIBPATH (it is */
  6. /* usually in your \TCPIP\DLL directory.  It was shipped with the      */
  7. /* August 1994 CSD for the TCP/IP base (UN64092).                      */
  8.  
  9. call load /* load functions if necessary */
  10.  
  11. say " Issue a GET method request to an HTTP server, and display complete response "
  12. parse arg server request .
  13. if server="" then do 
  14.     mehost=get_hostname()
  15.     say " Please enter server address (ENTER= " mehost ": "
  16.     parse pull server
  17.     if server="" then server=mehost
  18. end  /* Do */
  19. if request="" then  do
  20.   say " Please enter url to GET: "
  21.   parse pull request
  22. end
  23.  
  24. crlf    ='0d0a'x                        /* constants */
  25. family  ='AF_INET'
  26. httpport=80
  27.  
  28. rc=sockgethostbyname(server, "serv.0")  /* get dotaddress of server */
  29. if rc=0 then do; say 'Unable to resolve "'server'"'; exit; end
  30. dotserver=serv.0addr                    /* .. */
  31.  
  32. gosaddr.0family=family                  /* set up address */
  33. gosaddr.0port  =httpport
  34. gosaddr.0addr  =dotserver
  35.  
  36. gosock = SockSocket(family, "SOCK_STREAM", "IPPROTO_TCP")
  37.  
  38.  
  39. message='GET /'request' HTTP/1.0'crlf'HOST:'server||crlf
  40.  
  41. /*Note: uncomment these lines, and changes the "bytes=" ranges,
  42. if you only want a segment(s) of the URL*/
  43. /*
  44. message=message||"Connection:keep-alive"||crlf
  45. message=message||"Range:bytes=0-50,200-400"||crlf
  46. */
  47. message=message||'Referer:joes_bar'||crlf
  48.  
  49. message=message||crlf
  50. say message
  51.  
  52.  
  53. got=''
  54. rc = SockConnect(gosock,"gosaddr.0")
  55. if rc<0 then do; say 'Unable to connect to "'server'"'; exit; end
  56. rc = SockSend(gosock, message)
  57. say " rc " rc
  58. /* Now wait for the response */
  59. do r=1 by 1
  60.   rc = SockRecv(gosock, "response", 1000)
  61.   got=got||response
  62.   /* say '>'rc'>' response */
  63.   if rc<=0 then leave
  64.   end r
  65. rc = SockClose(gosock)
  66.  
  67. say 'Got' length(got) 'bytes of response:'
  68.  
  69. findit=crlf||crlf
  70. foo=pos(findit,got)
  71. say foo
  72. t1=substr(got,1,foo)
  73. say t1
  74. say " =--- writing results to doget.lst "
  75. t2=substr(got,foo+length(findit))
  76. tt='doget.lst'
  77. eek=charout(tt,t2,1)
  78. say eek
  79.  
  80. exit
  81.  
  82. /* --- Load the function library, if necessary --- */
  83. load:
  84. if \RxFuncQuery("SockLoadFuncs") then return      /* already there */
  85. call RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
  86. call SockLoadFuncs
  87. return
  88.  
  89. /* get the hostname (aa.bb.cc) for this machine */
  90. get_hostname: procedure
  91.     do queued(); pull .; end                   /* flush */
  92.     address cmd '@hostname'  '| rxqueue'    
  93.     parse pull hostname                        
  94.     return hostname
  95.  
  96.